package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.ImeId;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeImeid implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *WT,866248050395985,GETIMEID,164931,164932,866248050395985,A,2250.2243,N,11391.6211,E,0.14,332,020621,FFFFDFFF
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[3];
        String deviceTime = split[4];
        String imeid = split[5];//设备上报的imeid
        String lat = split[7];
        String lng = split[9];
        String speed = split[11];
        String orientation = split[12];
        String date = split[13];
        String deviceStatus = split[14];
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        List<Double> latlng = LocationUtils.transiformLatAndLng(lng, lat);
        mqLocationData.setLatitude(latlng.get(1));
        mqLocationData.setLongitude(latlng.get(0));
        ImeId imeId = new ImeId();
        imeId.setCommandNumber(commandNumber);
        imeId.setDeviceDate(date);
        imeId.setDeviceStatus(deviceStatus);
        imeId.setDeviceTime(deviceTime);
        imeId.setImei(imei);
        imeId.setLocationData(mqLocationData);
        imeId.setUpLoadImeId(imeid);
        return structureMessage(Constants.REPLY,Constants.CMD_GET_IMEI,false,"",imeId);
    }
}
